package com.atguigu.gmall.seckill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.seckill.pojo.SeckillOrder;
import com.atguigu.gmall.seckill.pojo.UserRecode;
import com.atguigu.gmall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: dongdong lau
 * @CreateTime: 2021/7/16 18:21
 * @Description: 秒杀订单controller层
 */
@RestController
@RequestMapping(value = "/seckill/order")
public class SeckillOrderController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 用户排队信息
     * @param time
     * @param skuId
     * @return
     */
    @GetMapping(value = "/add")
    public Result addSeckillOrder(String time,String skuId){
        String username = "dongdong";
        UserRecode userRecode = seckillService.addOrder(time, skuId, username);
        return Result.ok(userRecode);
    }

    /**
     * 根据用户id获取排队状态
     * @return
     */
    @GetMapping(value = "/getRecode")
    public Result getRecodeByUserId(){
        String username = "dongdong";
        UserRecode userRecode = seckillService.getUserRecode(username);
        return Result.ok(userRecode);
    }

    /**
     * 查询秒杀订单信息
     * @param order
     * @return
     */
    @GetMapping(value = "/getSeckillOrderList")
    public Result getSeckillOrderList(String order){
        String username = "dongdong";
        List<SeckillOrder> seckillOrder = seckillService.getSeckillOrder(username, order);
        return Result.ok(seckillOrder);
    }
}
